package com.mz.ozy.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.mz.ozy.R;
import com.mz.ozy.constants.Constants;
import com.mz.ozy.utils.glideUtils.GlideUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 部位适配器
 */
public class PhotoAdapter extends BaseAdapter {

    private List<String> mCourseList = new ArrayList<>();

    private Context mContext;


    public PhotoAdapter(Context context, List<String> listbean) {
        this.mContext = context;
        mCourseList = listbean;

    }

    public void setData(List<String> listbean) {
        mCourseList = listbean;
        notifyDataSetChanged();
    }

    public List<String> getCourseList() {
        return mCourseList;
    }

    @Override
    public int getCount() {
        if (mCourseList == null) {
            return 0;
        } else {
            return mCourseList.size();
        }
    }

    @Override
    public Object getItem(int position) {
        return mCourseList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_pevalute_photo, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        final String item = mCourseList.get(position);

        if (TextUtils.isEmpty(item)) {
            GlideUtils.loadImg(mContext, holder.mTypeTv, R.mipmap.pic_default_appeal);
        } else {
            GlideUtils.loadImg(mContext, holder.mTypeTv, Constants.Http.pic_host_address + item, R.mipmap.pic_default_appeal);
        }

        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.iv_item_live_pic)
        ImageView mTypeTv;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
